package paper.service;

import java.util.Iterator;
import java.util.List;

import keter.domain.Unit;
import keter.service.RoleService;
import keter.service.UnitService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import paper.dao.UserDao;
import paper.domain.User;

@Service
public class UserService {
    /**
     * Logger for this class
     */
    private static final Logger logger = LoggerFactory.getLogger(UserService.class);

    @Autowired
    private UserDao dao;
    
    @Autowired
    private RoleService rs;
    
    public UserDao getDao() {
		return dao;
	}

	public void setDao(UserDao dao) {
		this.dao = dao;
	}
    
    @Autowired
    private UnitService service;
    
    public List<User> findByTeacher(Long id){
        return dao.findByTeacher(id);
    }
 
    public void importStudent(List<User> list) {
        for (Iterator<User> iterator = list.iterator(); iterator.hasNext();) {
            User s = (User) iterator.next();
            if(s.getAccount().getUnit()!=null){
                //从数据库中找到当前代码对应的组织机构
                Unit u = service.findByCode(s.getAccount().getUnit().getCode());
                s.getAccount().setUnit(u);
            }
            
        }
        dao.saveList(list);
    }
}
